import MySQLdb
try:
    from taocode2.private_setting import *
except ImportError:
    pass

try:    
    conn=MySQLdb.connect(host=DATABASES['default']['HOST'],user=DATABASES['default']['USER'],passwd=DATABASES['default']['PASSWORD'],db=DATABASES['default']['NAME'],port=3306) 
    cur=conn.cursor() 
    memberCount=cur.execute('select * from taocode2_user;') 
    
    projectCount=cur.execute('select * from taocode2_project;') 
    
    yCommitSql='select * from taocode2_activity where act_type ="new_commit" and DATE(ctime) = DATE_SUB(CURDATE(),INTERVAL 1 DAY);'
    yesterdayCommit=cur.execute(yCommitSql) 
    
    yesterdayIssue=cur.execute('select * from taocode2_issue where DATE(ctime) = DATE_SUB(CURDATE(),INTERVAL 1 DAY);')
    yesterdayComment=cur.execute('select * from taocode2_issuecomment  where DATE(ctime) = DATE_SUB(CURDATE(),INTERVAL 1 DAY);')
    
    yesterdayIssues=yesterdayIssue+yesterdayComment
    
    updateSql='update taocode2_projectreport set report_cycle=%s , download_times=%s ,commit_times =%s , issue_times =%s ,mtime=now() where id=9999'
    args=(int(projectCount), int(memberCount), int(yesterdayCommit),int(yesterdayIssues))
    cur.execute(updateSql,args )
    conn.commit()   
  
    cur.close() 
    conn.close() 
    
    
    
except MySQLdb.Error,e: 
    print "Mysql Error %d: %s" % (e.args[0], e.args[1]) 
